/**
 * iview table 配置，需将当前的组件引入进来，否则无法调用当前当前组件的method
 * 借用中间变量table,在挂载组件时将上下文引入进来
 * @author sangtao
 * @type {{table: {}, premisesColumns: *[]}}
 */
function fmtDate(obj) {
  if (obj) {
    var date = new Date(obj);
    var y = 1900 + date.getYear();
    var m = "0" + (date.getMonth() + 1);
    var d = "0" + date.getDate();

    var h = date.getHours();
    h = h < 10 ? "0" + h : h;

    var minute = date.getMinutes();
    minute = minute < 10 ? "0" + minute : minute;

    var second = date.getSeconds();
    second = second < 10 ? "0" + second : second;

    return (
      y +
      "-" +
      m.substring(m.length - 2, m.length) +
      "-" +
      d.substring(d.length - 2, d.length) +
      " " +
      h +
      ":" +
      minute +
      ":" +
      second
    );
  } else {
    return "";
  }
}
var config = {
  table: {},
  cusPreColumns: [
    {
      type: "index",
      title: "序号",
      key: "",
      fixed: "left",
      width: 70,
      align: "center",
    },
    {
      title: "楼盘名称",
      key: "premisesName",
      fixed: "left",
      width: 150,
      align: "center",
    },
    {
      title: "客户姓名",
      key: "name",
      fixed: "left",
      width: 100,
      align: "center",
    },
    {
      title: "客户电话",
      key: "mobile",
      fixed: "left",
      width: 115,
      align: "center",
    },
    { title: "报备类型", key: "reportType", width: 100, align: "center" },
    {
      title: "报备人姓名",
      key: "",
      width: 100,
      align: "center",
      render: (h, params) => {
        return h(
          "div",
          params.row.reportType == "经纪人报备"
            ? params.row.staffName
            : params.row.assistantName
        );
      },
    },
    {
      title: "报备人电话",
      key: "",
      width: 115,
      align: "center",
      render: (h, params) => {
        return h(
          "div",
          params.row.reportType == "经纪人报备"
            ? params.row.staffPhone
            : params.row.assistantPhone
        );
      },
    },
    {
      title: "报备状态",
      key: "cusNewStatusName",
      width: 120,
      align: "center",
      render: (h, params) => {
        return h("div", [
          h(
            "Tag",
            {
              props: {
                color: "green",
              },
            },
            params.row.cusNewStatusName
          ),
        ]);
      },
    },
    {
      title: "交易状态",
      key: "confirmStatusName",
      width: 110,
      align: "center",
      render: (h, params) => {
        return h("div", [
          h(
            "Tag",
            {
              props: {
                color: "green",
              },
            },
            params.row.confirmStatusName
          ),
        ]);
      },
    },
    {
      title: "按揭状态",
      key: "mortgageStatusName",
      width: 100,
      align: "center",
    },
    { title: "经纪公司", key: "staffCompanyName", width: 150, align: "center" },
    {
      title: "所在部门",
      key: "staffDepartmentName",
      width: 150,
      align: "center",
    },
    // { title: "机构门店", key: "staffStoreName", width: 150, align: "center" },
    // { title: "机构组别", key: "staffGroupName", width: 150, align: "center" },
    { title: "经纪人姓名", key: "staffName", width: 100, align: "center" },
    { title: "经纪人电话", key: "staffPhone", width: 115, align: "center" },
    { title: "渠道经理", key: "principalName", width: 100, align: "center" },
    {
      title: "渠道经理电话",
      key: "principalPhone",
      width: 115,
      align: "center",
    },
    {
      title: "报备时间",
      key: "createTime",
      width: 170,
      align: "center",
      render: (h, params) => {
        return h("div", fmtDate(params.row.createTime));
      },
    },
    {
      title: "首付交齐",
      key: "payFinish",
      width: 150,
      align: "center",
      render: (h, params) => {
        return h(
          "div",
          params.row.payFinish === "1"
            ? "是"
            : params.row.payFinish === "0"
            ? "否"
            : ""
        );
      },
    },
    {
      title: "操作",
      key: "action",
      fixed: "right",
      width: 270,
      align: "center",
      render: (h, params) => {
        return h("div", [
          h(
            "Button",
            {
              props: {
                type: "warning",
                size: "small",
              },
              style: {
                marginRight: "5px",
              },
              on: {
                click: () => {
                  config.table.toDetail(params.row.id);
                },
              },
            },
            "查看"
          ),
          h(
            "Button",
            {
              props: {
                type: "warning",
                size: "small",
              },
              style: {
                marginRight: "5px",
              },
              on: {
                click: () => {
                  config.table.toCopy(params.row);
                },
              },
            },
            "复制"
          ),
          h(
            "Button",
            {
              props: {
                type: "warning",
                size: "small",
              },
              style: {
                marginRight: "5px",
                /* display:config.table.userAuthResources.indexOf(config.table.resourcesList.menu_0005_0001_0004) >= 0?'':'none'*/
              },
              on: {
                click: () => {
                  config.table.toFollow(params.row.id);
                },
              },
            },
            "写跟进"
          ),
          h(
            "Button",
            {
              props: {
                type: "warning",
                size: "small",
              },
              style: {
                marginRight: "5px",
                display:
                  params.row.customerStatus == -1 &&
                  params.row.disableType == 3 &&
                  params.row.afreshNum != 1
                    ? ""
                    : "none",
              },
              on: {
                click: () => {
                  config.table.toReport(params.row.id);
                },
              },
            },
            "重新发起"
          ),
          h(
            "Button",
            {
              props: {
                type: "warning",
                size: "small",
              },
              style: {
                marginRight: "5px",
                display:
                  params.row.customerStatus == -1 &&
                  (params.row.complaintsNumber == 0 ||
                    null == params.row.complaintsNumber) &&
                  params.row.disableType == 1
                    ? ""
                    : "none",
              },
              on: {
                click: () => {
                  config.table.reSubmit(params.row.id, params.row.premisesId);
                },
              },
            },
            "申诉"
          ),
          h(
            "Button",
            {
              props: {
                type: "warning",
                size: "small",
              },
              style: {
                marginRight: "5px",
                display: params.row.customerStatus == "10" ? "" : "none",
              },
              on: {
                click: () => {
                  config.table.toRemindExamine(JSON.stringify(params.row));
                },
              },
            },
            "提醒到访审核"
          ),
        ]);
      },
    },
  ],
};
export default {
  config,
};
